package cn.cs.yangtai.service.impl;

import cn.cs.yangtai.entity.Classification;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.mapper.ClassificationMapper;
import cn.cs.yangtai.service.ClassificationService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * (Classification)表服务实现类
 *
 * @author makejava
 * @since 2024-12-12 09:03:50
 */
@Service("classificationService")
public class ClassificationServiceImpl implements ClassificationService {
    @Resource
    private ClassificationMapper classificationMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param fId 主键
     * @return 实例对象
     */
    @Override
    public Classification queryById(Integer fId) {
        return this.classificationMapper.queryById(fId);
    }

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @Override
    public PageResult<Classification> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageHelper.startPage(cuttentPage,pageSize);
        Page<Classification> classifications =classificationMapper.queryAllByLimit(new Page<>());
        return PageResult.restPage(classifications);
    }

    /**
     * 新增数据
     *
     * @param classification 实例对象
     * @return 实例对象
     */
    @Override
    public Classification insert(Classification classification) {
        this.classificationMapper.insert(classification);
        return classification;
    }

    /**
     * 修改数据
     *
     * @param classification 实例对象
     * @return 实例对象
     */
    @Override
    public Classification update(Classification classification) {
        this.classificationMapper.update(classification);
        return this.queryById(classification.getFId());
    }

    /**
     * 通过主键删除数据
     *
     * @param fId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer fId) {
        return this.classificationMapper.deleteById(fId) > 0;
    }
}
